$(document).ready(function() {         
			$("#schoolCardinfo").jqGrid(
			{
				url : global_url+global_urijs+'schoolica_search_admin'+global_suffix+"?sid="+global_sid,
				datatype : "json",
				mtype : 'GET',
				height:300, 
				width:770,
				colNames : [ 'IC卡号', '归属','卡状态','操作','绑定ic卡','状态','icid' ],
				colModel : [ {name : 'cardnum',index : 'cardnum',width : 150,align:'center'}, 
							 {name : 'name_card',index : 'name_card',width : 150,sortable : false,align:'center'},
							 {name : 'state_str',index : 'state_str',width : 100,sortable : false,align:'center'}, 
							 {name : 'option',index : 'option',width : 100,sortable : false,align:'center'}, 
							 {name : 'bindic',index : 'bindic',width : 200,sortable : false,align:'center'}, 
							 {name:'state',index:'state',hidden:true},
							 {name:'icid',index:'icid',hidden:true}
						   ],
				//autowidth:true,
				jsonReader : {
					root : "schoolIcCardList",
					page : "page",
					total : "page_count",
					repeatitems : false
				},
				pager : jQuery("#schoolCardpage"),
				prmNames : {
					page : "page",
					sort : "sort"
				},
				rowNum : 10,
				//rowList: [10, 20, 30],
				sortname : 'cardnum',
				hidegrid : false,
				sortorder : 'asc',
				viewrecords : true,
				caption : 'IC卡信息',
				gridComplete:function(){
					var ids=jQuery("#schoolCardinfo").jqGrid('getDataIDs');
					for(var i=0; i<ids.length; i++){
						var id=ids[i];   
						var state_str = jQuery("#schoolCardinfo").jqGrid('getRowData', id).state_str;
						var name = jQuery("#schoolCardinfo").jqGrid('getRowData', id).name_card;
						jh = "<a href='javascript:;'  class='jqtrow' onclick='upTel_qd(" + id + ")'>启用</a>"; 
						zx = "<a href='javascript:;'  class='jqtrow' onclick='upTel_zx(" + id + ")'>注销</a>"; 
						hs = "<a href='javascript:;'  class='jqtrow' onclick='delTel(" + id + ")'>回收</a>"; 
						stub = "<a href='javascript:;'  class='jqtrow' onclick='bind_s(" + id + ")'>学生绑卡</a>";
						teab = "<a href='javascript:;'  class='jqtrow' onclick='bind_t(" + id + ")'>教师绑卡</a>";						
						var re = jh;
						var st = "已绑定";
						if(state_str=="启用"){
							re = zx;
						}
						if(name=="未分派"){
							st = stub+" "+teab;
						}
						
						jQuery("#schoolCardinfo").jqGrid('setRowData', ids[i],{ option:re,bindic:st});
					}
				}
			}).navGrid("#schoolCardpage", {edit : false,add : false,del : false,search : false});
		});

function delTel(id){
	 $("#deltname").html(jQuery("#schoolCardinfo").jqGrid('getRowData', id).cardnum);
	 $(function() {
			$( "#ic_del" ).dialog({
				modal: true,
				resizable: false,
				buttons: {
					"回收": function() {
						var fun = function(data){
							if(1==data.s){
								 $().message("回收成功!");
								 $("#schoolCardinfo").trigger("reloadGrid");
								 $("#ic_del").dialog( "close" );
							}else{
								 $().message("回收失败!");
							}
						};
						exeAjax(ajaxUrl(global_url+global_urijs+'schoolica_delete'+global_suffix), fun, 
								{"icid" :jQuery("#schoolCardinfo").jqGrid('getRowData', id).icid});
					},"取消": function() {
						$( this ).dialog( "close" );
					}
				}
			});
		});
}

function upTel_qd(id){
	var icid = jQuery("#schoolCardinfo").jqGrid('getRowData', id).icid;
	var fun = function(data) {
		$("#schoolCardinfo").trigger("reloadGrid");
	};
	exeAjax(ajaxUrl(global_url+global_urijs+'schoolica_updateSchoolIcardState'+global_suffix), fun, 
		{"sid" : global_sid,"icid" :icid,"state":10});
}

function upTel_zx(id){
	var icid = jQuery("#schoolCardinfo").jqGrid('getRowData', id).icid;
	var fun = function(data) {
		$("#schoolCardinfo").trigger("reloadGrid");
	};
	exeAjax(ajaxUrl(global_url+global_urijs+'schoolica_updateSchoolIcardState'+global_suffix), fun, 
		{"sid" : global_sid,"icid" :icid,"state":20});
}

// 显示学生绑卡记录
function addStudentIc(){
	//教师邀请记录
	$("#addStuCardinfo").jqGrid({                
		url:global_url+global_urijs+'schoolica_searchAddStuIcList'+global_suffix+"?sid="+global_sid,                
		datatype:"json",                
		mtype:'GET', 
		height:'250',
		width:'740',
		colNames:['姓名','班级','卡号','绑定日期'],                
		colModel:[                    
		{name:'sname',index:'sname',width:120,align:'center'}, 
		{name:'name_classes',index:'name_classes',width:120,align:'center'},  
		{name:'cardnum',index:'cardnum',width:120,align:'center'},                    
		{name:'ctime_str',index:'ctime_str',width:120,align:'center', sortable:false},
		],
		//autowidth:true,
		jsonReader: {
			root:"classStudentList",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery('#addStuCardpage'),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'ctime_str',
		hidegrid: false,
		sortorder: 'desc',
		viewrecords: true,
		caption: '',
		gridComplete:function(){
			var ids=jQuery("#addStuCardinfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i];   
				
				jQuery("#addStuCardinfo").jqGrid('setRowData', ids[i]);
			}
		}
	}).navGrid("#addStuCardpage", { edit: false, add: false, del: false, search: false });
}

//显示教师绑卡记录
function addTeacherIc(){
	//教师邀请记录
	$("#addTeaCardinfo").jqGrid({                
		url:global_url+global_urijs+'schoolica_searchAddTeaIcList'+global_suffix+"?sid="+global_sid,                
		datatype:"json",                
		mtype:'GET', 
		height:'250',
		width:'740',
		colNames:['姓名','班级','卡号','绑定日期'],                
		colModel:[                    
		{name:'tname',index:'tname',width:120,align:'center'}, 
		{name:'classNams_in',index:'classNams_in',width:120,align:'center'},  
		{name:'cardnum',index:'cardnum',width:120,align:'center'},                    
		{name:'ctime_str',index:'ctime_str',width:120,align:'center', sortable:false},
		],
		//autowidth:true,
		jsonReader: {
			root:"schoolTeacherList",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery('#addTeaCardpage'),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'ctime_str',
		hidegrid: false,
		sortorder: 'desc',
		viewrecords: true,
		caption: '',
		gridComplete:function(){
			var ids=jQuery("#addTeaCardinfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i];   
				
				jQuery("#addTeaCardinfo").jqGrid('setRowData', ids[i]);
			}
		}
	}).navGrid("#addTeaCardpage", { edit: false, add: false, del: false, search: false });
}


